package com.zut.controller;

import com.zut.domain.Recruitment;
import com.zut.service.RecruitmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/recruitment")
public class RecruitmentController {

    @Autowired
    private RecruitmentService recruitmentService;

    /*得到所有招聘信息*/
    @GetMapping
    public Result getAll() {
        List<Recruitment> recruitments = recruitmentService.getAll();
        Integer code = recruitments != null ? Code.GET_OK : Code.GET_ERR;
        String msg = recruitments != null ? "" : "数据查询失败，请重试！";
        return new Result(code, recruitments, msg);
    }

    /*创建招聘信息*/
    @PostMapping
    public Result insert(@RequestBody Recruitment recruitment) {
        boolean flag = recruitmentService.insert(recruitment);
        return new Result(flag ? Code.SAVE_OK : Code.SAVE_ERR, flag);
    }

    /*根据id删除诈骗品信息*/
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable String id) {
        boolean flag = recruitmentService.deleteById(id);
        return new Result(flag ? Code.DELETE_OK : Code.DELETE_ERR, flag);
    }

    /*修改招聘信息*/
    @PutMapping
    public Result Update(@RequestBody Recruitment recruitment) {
        boolean flag = recruitmentService.update(recruitment);
        return new Result(flag ? Code.UPDATE_OK : Code.UPDATE_ERR, flag);
    }
}
